using System;

namespace RapidHDL
{
	/// <summary>
	/// Summary description for Test.
	/// </summary>
	public class Test
	{
		/*AndGate oAndGate;
		OrGate oOrGate;
		Not oNot;
		NotGate oNotGate;*/
		RapidHardware oRapidHardware;
		/*Xor oXor;
        Adder oAdder;*/
        UpCounter oUpCounter;

        //ConstantSelect oCSelect;

		public Test()
		{
			oRapidHardware = new RapidHardware();
            
            //oRapidHardware.Structure.AddMainClock(10);

            oRapidHardware.Structure.TopLevelComponent.AddMainClock(10);
            oRapidHardware.Structure.TopLevelComponent.AddMainReset();            
            
            oUpCounter = new UpCounter(oRapidHardware.Structure.TopLevelComponent, "counter", oRapidHardware.Structure.TopLevelComponent.MainClock , 4, true, true, 0, 10, 1);
            //oRapidHardware.SystemInterface.AddSignalSource("reset_in",oUpCounter.ResetIn,0);
            oRapidHardware.SystemInterface.AddSignalSource("enable",oUpCounter.EnableIn,0);
            oUpCounter.ResetIn.Connection = oRapidHardware.Structure.TopLevelComponent.MainReset;
            //oUpCounter.EnableIn.Connection = oRapidHardware.Structure.TopLevelComponent.StartIn;

            

            //oCSelect = new ConstantSelect(oRapidHardware.Structure.TopLevelComponent, "cSelect", 4, 2);

			//oAndGate = new AndGate(oRapidHardware.Structure.TopLevelComponent,"and",2);
			//oOrGate = new OrGate(oRapidHardware.Structure.TopLevelComponent,"or",2);
			//oNot = new Not(oRapidHardware.Structure.TopLevelComponent,"not");
			//oNotGate = new NotGate(oRapidHardware.Structure.TopLevelComponent,"not_gate",2);
			//oXor = new Xor(oRapidHardware.Structure.TopLevelComponent,"xor");
            
            //oAdder = new Adder(oRapidHardware.Structure.TopLevelComponent, "adder", 3, 2, true);
            oRapidHardware.Structure.GenerateStructure();

            //oRapidHardware.SystemInterface.AddSignalView("counter.reset_to.not_sel.In");
            //oRapidHardware.SystemInterface.AddSignalView("counter.reset_to.not_sel.Out");
            //oRapidHardware.SystemInterface.AddSignalView("counter.reset_to.and0.In");
            oRapidHardware.SystemInterface.AddSignalView("counter.reset_to.and0.Out");
            oRapidHardware.SystemInterface.AddSignalView("counter.adder.InA");
            oRapidHardware.SystemInterface.AddSignalView("counter.adder.InB");
            oRapidHardware.SystemInterface.AddSignalView("counter.adder.Out");
            //oRapidHardware.SystemInterface.AddSignalView("counter.adder.Out");
            oRapidHardware.SystemInterface.AddSignalView("counter.count_reg.InputNodes", oUpCounter.CountOut);            
            oRapidHardware.SystemInterface.AddSignalView("counter.count_reg.OutputNodes", oUpCounter.CountOut);
            

		}

		public void DoIt()
		{
			//oRapidHardware.Structure.TestAll("");
            //return;

            oRapidHardware.Simulation.SetComponentTrace("counter.adder","output");
            oRapidHardware.Simulation.SetComponentTrace("counter.count_by", "output");
            oRapidHardware.Simulation.SetComponentTrace("counter.count_reg", "output");
            oRapidHardware.Simulation.SetNodeVectorTrace("counter.adder.Out", "stabilize");
            
            //oRapidHardware.Simulation.SetComponentTrace("counter.reset_to.and0", "output");
            //oRapidHardware.Simulation.SetComponentTrace("counter.reset_to.not_sel", "output");
            //oRapidHardware.Simulation.SetNodeVectorTrace("counter.reset_to.and0.In", "stabilize");
            //oRapidHardware.Simulation.SetNodeVectorTrace("counter.reset_to.and0.Out", "stabilize");
            //oRapidHardware.Simulation.SetNodeVectorTrace("counter.reset_to.not_sel.Out", "stabilize");

            //oRapidHardware.InternalLog.DisplayLogs.Add(LogType.VerilogTrace);
			//oRapidHardware.InternalLog.EnableDisplayToConsole = true;
			oRapidHardware.Structure.TransformStructure(StructureTransformType.Verilog);
            return;


            /*
            //oRapidHardware.Structure.AddMainClock(1);
            oRapidHardware.Structure.TopLevelComponent.MainClock.Frequency = 1;
            oRapidHardware.SystemInterface.SetSignal("RESET", 0);
            oRapidHardware.SystemInterface.SetSignal("START", 0);
            oRapidHardware.Simulation.Clock.DoClock(3);
            oRapidHardware.SystemInterface.SetSignal("RESET", 1);
            oRapidHardware.SystemInterface.SetSignal("START", 1);
            oRapidHardware.Simulation.Clock.DoClock(3);
            System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            oRapidHardware.SystemInterface.ListAll();
            System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");

            oRapidHardware.SystemInterface.SetSignal("RESET", 0);
            oRapidHardware.SystemInterface.SetSignal("START", 1);
            oRapidHardware.Simulation.Clock.DoClock(9.0);
            System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            oRapidHardware.SystemInterface.ListAll();
            System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");


            oRapidHardware.SystemInterface.SetSignal("RESET", 0);
            oRapidHardware.Simulation.Clock.DoClock(3);
            System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            oRapidHardware.SystemInterface.ListAll();
            System.Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");

            */

			//oAndGate.BaseTestComponent("");
			//oRapidHardware.Simulation.VerifyComponent( oAndGate);
			//oAndGate.InputNodes[0].NodeState = NodeState.High;
			//oAndGate.InputNodes[1].NodeState = (NodeState)0;
			//oRapidHardware.Simulation.Clock.DoClock(1);
			//System.Windows.Forms.MessageBox.Show(oAndGate.OutputNodes[0].ToString());
		}

	}
}
